<template>
  <view class="detail-page">
    <!-- 顶部状态 -->
    <view class="status-section">
      <image v-if="orderInfo.status === 'completed'" class="status-icon" src="@/static/order/icon-check.png" />
      <view v-else class="progress-circle">
        <text class="percentage">{{ orderInfo.percentage }}%</text>
        <text class="status-text">正在充电</text>
      </view>
    </view>

    <!-- 充电信息 -->
    <view class="info-card">
      <view class="card-title">充电信息</view>
      <view class="info-row">
        <text class="label">订单编号：</text>
        <text class="value">{{ orderInfo.orderNo }}</text>
      </view>
      <view class="info-row">
        <text class="label">充电站：</text>
        <text class="value">{{ orderInfo.stationName }}</text>
      </view>
      <view class="info-row">
        <text class="label">起始时间：</text>
        <text class="value">{{ orderInfo.startTime }} / {{ orderInfo.endTime }}</text>
      </view>
      <view class="info-row">
        <text class="label">车辆信息：</text>
        <text class="value">{{ orderInfo.carInfo }}</text>
      </view>
      <view class="info-row">
        <text class="label">充电时长：</text>
        <text class="value">{{ orderInfo.chargingTime }}</text>
      </view>
      <view class="info-row">
        <text class="label">充电度数：</text>
        <text class="value">{{ orderInfo.chargingDegree }}度</text>
      </view>
    </view>

    <!-- 费用明细 -->
    <view class="info-card">
      <view class="card-title">费用明细</view>
      <view class="fee-row">
        <text class="label">订单金额</text>
        <text class="value">¥{{ orderInfo.totalFee }}</text>
      </view>
      <view class="fee-row" v-if="orderInfo.couponAmount">
        <text class="label">优惠卷</text>
        <text class="value discount">-{{ orderInfo.couponAmount }}元</text>
      </view>
      <view class="fee-row" v-if="orderInfo.pointsAmount">
        <text class="label">积分抵扣<u-icon name="info-circle" size="28" color="#999" /></text>
        <text class="value discount">-{{ orderInfo.pointsAmount }}元</text>
      </view>
      <view class="total-fee">
        <text>合计：</text>
        <text class="amount">¥{{ orderInfo.finalFee }}</text>
      </view>
    </view>

    <!-- 底部按钮 -->
    <view class="bottom-btn" v-if="orderInfo.status === 'charging'">
      <u-button type="primary" @click="stopCharging">结束充电</u-button>
    </view>
    <view class="bottom-btn" v-else>
      <u-button type="primary" @click="goBack">确定并返回</u-button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      orderId: '',
      orderInfo: {
        status: 'charging', // charging, completed
        percentage: 68,
        orderNo: '202412240034123',
        stationName: '白云科技充电桩',
        startTime: '12-24 12:12',
        endTime: '12-24 13:23',
        carInfo: '吉利汽车 / 浙A·34215',
        chargingTime: '59分钟',
        chargingDegree: '56.34',
        totalFee: '23.8',
        couponAmount: '3.00',
        pointsAmount: '0.50',
        finalFee: '20.3'
      }
    }
  },
  onLoad(options) {
    this.orderId = options.id
    this.getOrderDetail(options.id)
  },
  methods: {
    getOrderDetail(id) {
      // TODO: 调用获取订单详情接口
    },
    stopCharging() {
      uni.showModal({
        title: '提示',
        content: '确定要结束充电吗？',
        success: (res) => {
          if (res.confirm) {
            // TODO: 调用结束充电接口
            uni.showToast({
              title: '已结束充电',
              icon: 'success'
            })
          }
        }
      })
    },
    goBack() {
      uni.navigateBack()
    }
  }
}
</script>

<style lang="scss" scoped>
.detail-page {
  min-height: 100vh;
  background: #F5F5F5;
  padding: 20rpx;
}

.status-section {
  background: #FFFFFF;
  border-radius: 16rpx;
  padding: 60rpx 0;
  margin-bottom: 20rpx;
  display: flex;
  justify-content: center;
  align-items: center;

  .status-icon {
    width: 120rpx;
    height: 120rpx;
  }

  .progress-circle {
    text-align: center;

    .percentage {
      font-size: 48rpx;
      font-weight: bold;
      color: #333;
      display: block;
    }

    .status-text {
      font-size: 28rpx;
      color: #666;
      margin-top: 12rpx;
    }
  }
}

.info-card {
  background: #FFFFFF;
  border-radius: 16rpx;
  padding: 32rpx;
  margin-bottom: 20rpx;

  .card-title {
    font-size: 32rpx;
    font-weight: 500;
    color: #333;
    margin-bottom: 24rpx;
    position: relative;
    padding-left: 20rpx;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 6rpx;
      height: 28rpx;
      background: #1296db;
      border-radius: 3rpx;
    }
  }

  .info-row {
    display: flex;
    margin-bottom: 20rpx;
    font-size: 28rpx;
    line-height: 40rpx;

    &:last-child {
      margin-bottom: 0;
    }

    .label {
      color: #999;
      min-width: 140rpx;
    }

    .value {
      color: #333;
      flex: 1;
    }
  }

  .fee-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20rpx;
    font-size: 28rpx;
    line-height: 40rpx;

    .label {
      color: #333;
      display: flex;
      align-items: center;
      gap: 8rpx;
    }

    .value {
      color: #333;

      &.discount {
        color: #FF4D4F;
      }
    }
  }

  .total-fee {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 32rpx;
    padding-top: 24rpx;
    border-top: 2rpx solid #F5F5F5;
    font-size: 28rpx;
    color: #333;

    .amount {
      font-size: 36rpx;
      font-weight: bold;
      margin-left: 8rpx;
    }
  }
}

.bottom-btn {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20rpx 32rpx;
  padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  background: #FFFFFF;
  box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.05);
}
</style>
